{
Traviesadora beta 0.2.0.13.33 (30.11.2008)
LastMod: 11.12.2008 by Prof1983

Copyright 2008, travieorama@googlemail.com

This file is part of the taviesadora project

taviesadora is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

taviesadora is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
}
unit LinkToEd2kWin;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ShellApi, MovieLibrary;

type
  TFrmLinkToEd2k = class(TForm)
    btnClose: TButton;
    lblText: TLabel;
    memoed2k: TMemo;
    btnAdd: TButton;
    OpenDialog1: TOpenDialog;
    constructor Create(Owner:TComponent;MovieName:string;ed2k:string;Lib:TMovieLib);
    procedure btnCloseClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure memoed2kClick(Sender: TObject);
    procedure btnAddClick(Sender: TObject);
  private
    OrigAskLink: string;
    MovieLib: TMovieLib;
  end;

var
  FrmLinkToEd2k: TFrmLinkToEd2k;

implementation

uses
  Movie;

{$R *.dfm}

procedure TFrmLinkToEd2k.btnCloseClick(Sender: TObject);
begin
  if Owner <> nil then
    if (Owner is TfrmMovie) then
      (Owner as TfrmMovie).CantFindMovie;
  close;
end;

constructor TFrmLinkToEd2k.Create(Owner: TComponent; MovieName, ed2k: string;Lib:TMovieLib);
var
  i:integer;
begin
  inherited create(Owner);
  MovieLib := Lib;
  OrigAskLink := ed2k;
  i := 1;
  while i < length(ed2k) do begin
    if ed2k[i]='~' then
      delete(ed2k,i,1)
    else
      inc(i);
  end;
  ed2k := 'ed2k://|'+ed2k+'|/';
  lblText.Caption := 'Your Partner asked you to watch the Movie '+MovieName+' which doesnt exist in your library. '+
                  'If your are sure you are Owner of the Copyrights or the content is free of rights, you can download '+
                  'this Movie via eDonky or EMule with clicking on this link:';
  memoed2k.text := ed2k;
  show;
end;

procedure TFrmLinkToEd2k.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := cafree;
end;

procedure TFrmLinkToEd2k.memoed2kClick(Sender: TObject);
begin
  ShellExecute(handle,	// handle to parent window
    'open',	// pointer to string that specifies operation to perform
    PCHar(memoed2k.text),	// pointer to filename or folder name string
    '',	// pointer to string that specifies executable-file parameters
    '',	// pointer to string that specifies default directory
    SW_SHOW	); 	// whether file is shown when opened)
  close;
end;

procedure TFrmLinkToEd2k.btnAddClick(Sender: TObject);
begin
  if OpenDialog1.Execute then begin
    if MovieLib <> nil then begin
      MovieLib.AddMovie(OpenDialog1.FileName);
      if Owner <> nil then
        if (Owner is TfrmMovie) then
          (Owner as TfrmMovie).PlayByAskString(OrigAskLink);
    end;
    close;
  end;
end;

end.
